package cn.smile;

import cn.smile.entity.Order;
import cn.smile.stream.RabbitMqStreamConfig;
import cn.smile.utils.GsonTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableEurekaClient
@EnableBinding(RabbitMqStreamConfig.class)
@RestController
public class SpringcloudStreamApplication {

    @Autowired
    private RabbitMqStreamConfig rabbitMqStreamConfig;


    public static void main(String[] args) {
        SpringApplication.run(SpringcloudStreamApplication.class, args);
    }

    @GetMapping("/send")
    public boolean send() throws Exception{
        //发送字符串
        //rabbitMqStreamConfig.send().send(MessageBuilder.withPayload("Hello".getBytes("UTF-8")).build());
        final Order order = new Order("你好");
        final String json = GsonTool.objectToJson(order);
        //发送对象
        boolean send = rabbitMqStreamConfig.send().send(MessageBuilder.withPayload(json.getBytes("UTF-8")).build());
        return send;
    }

}
